//package com.jsyl.qies.business.service.impl;
//
//import com.jsyl.qies.business.domain.education.ChildSchedule;
//import com.jsyl.qies.business.domain.Question;
//import com.jsyl.qies.business.domain.StudentTrainingItems;
//import com.jsyl.qies.business.dto.ChildScheduleDTO;
//import com.jsyl.qies.business.dto.ConsolidateDTO;
//import com.jsyl.qies.business.dto.TeacherScheduleDTO;
//import com.jsyl.qies.business.mapper.ChildScheduleMapper;
//import com.jsyl.qies.business.mapper.QuestionMapper;
//import com.jsyl.qies.business.mapper.StudentTrainingItemsMapper;
//import com.jsyl.qies.business.service.IChildScheduleService;
//import com.jsyl.qies.business.vo.ChildScheduleVO;
//import com.jsyl.qies.common.exception.BusinessException;
//import com.jsyl.qies.common.utils.DateUtils;
//import com.jsyl.qies.common.utils.StringUtils;
//import org.apache.commons.collections.CollectionUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.util.ArrayList;
//import java.util.List;
//
//@Service
//public class ChildScheduleServiceImpl implements IChildScheduleService {
//
//    @Autowired
//    private ChildScheduleMapper childScheduleMapper;
//
//    @Autowired
//    private StudentTrainingItemsMapper studentTrainingItemsMapper;
//
//    @Autowired
//    private QuestionMapper questionMapper;
//
//    @Override
//    public List<ChildScheduleVO> selectChildScheduleList(ChildScheduleDTO childScheduleDTO) {
//        List<ChildScheduleVO> list = new ArrayList<>();
//        List<ChildSchedule> childScheduleList = childScheduleMapper.selectChildScheduleList(childScheduleDTO);
//        if (CollectionUtils.isNotEmpty(childScheduleList)) {
//            for (ChildSchedule schedule : childScheduleList) {
//                ChildScheduleVO vo = new ChildScheduleVO();
//                vo.setChildId(schedule.getChildId());
//                vo.setChildScheduleId(schedule.getId());
//                vo.setChildName(schedule.getChildName());
//                vo.setStart(schedule.getState());
//                vo.setDay(DateUtils.getMonthEndDay());
//                list.add(vo);
//            }
//        }
//        return list;
//    }
//
//    @Override
//    public List<StudentTrainingItems> selectByChildScheduleId(Long childScheduleId) {
//        List<StudentTrainingItems> list = studentTrainingItemsMapper.selectByChildScheduleId(childScheduleId);
//        for (StudentTrainingItems studentTrainingItems : list) {
//            // 老师调整标准之后，刷新的时候将老师修改的标准替换上去
//            if (!StringUtils.isEmpty(studentTrainingItems.getTeacherRevisedContent())) {
//                String reachTheStandard = studentTrainingItems.getReachTheStandard();
//                String replace = reachTheStandard.replace(studentTrainingItems.getResearchRevisedContent(), studentTrainingItems.getTeacherRevisedContent());
//                studentTrainingItems.setReachTheStandard(replace);
//            }
//        }
//        return list;
//    }
//
//    @Override
//    public int editSchedule(TeacherScheduleDTO teacherScheduleDTO) {
//        StudentTrainingItems studentTrainingItems = studentTrainingItemsMapper.selectById(teacherScheduleDTO.getStudentTrainingItemsId());
//        studentTrainingItems.setTeacherRevisedContent(teacherScheduleDTO.getTeacherRevisedContent());
//        return studentTrainingItemsMapper.update(studentTrainingItems);
//    }
//
//    @Override
//    public List<Question> addConsolidate(Long childId, String lastMonth) {
//        // TODO 需巩固项目需排除掉已完成的项目
//        String questionIds = studentTrainingItemsMapper.selectConsolidateByChildId(childId, lastMonth);
//        List<Question> question = questionMapper.selectByIds(questionIds);
//        return question;
//    }
//
//    @Override
//    public StudentTrainingItems selectByStudentTrainingItemsId(Long studentTrainingItemsId) {
//        return studentTrainingItemsMapper.selectById(studentTrainingItemsId);
//    }
//
//    @Override
//    public int addConsolidateList(ConsolidateDTO consolidateDTO) {
//        int i = 0;
//        // 获取选择的巩固项目
//        String ids = consolidateDTO.getIds();
//        String[] questionIds = ids.split(",");
//        // 查询这期已确定的题目
//        List<StudentTrainingItems> list = studentTrainingItemsMapper.selectByChildScheduleIdAndIsConfirm(consolidateDTO.getChildScheduleId());
//        // 比对是否有重复的题目
//        for (StudentTrainingItems studentTrainingItems : list) {
//            Long questionId = studentTrainingItems.getQuestionId();
//            for (int j = 0; j < questionIds.length; j++) {
//                if (questionIds[i].equals(questionId)) {
//                    throw new BusinessException("题目已存在。");
//                }
//            }
//        }
//        // 无重复题目则将项目保存
//        questionMapper.selectById(null);
//        i += studentTrainingItemsMapper.insert(null);
//        return i;
//    }
//
//}
